package luminus.origin.commands

import luminus.origin.utils.Configurations
import luminus.origin.utils.sendWithPrefix
import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
import taboolib.common.LifeCycle
import taboolib.common.TabooLib
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.command.*
import taboolib.common.platform.function.info
import taboolib.common.platform.function.pluginVersion
import taboolib.module.lang.Language
import taboolib.module.lang.sendLang
import taboolib.platform.util.sendLang

@CommandHeader("luminus")
object BaseCommand {
    @CommandBody(optional = true, permission = "luminus", permissionDefault = PermissionDefault.TRUE)
    val info = mainCommand {
        execute<ProxyCommandSender> { sender, _, _ ->
            sender.sendWithPrefix("Version $pluginVersion")
        }
    }

    @CommandBody(optional = true, permission = "luminus.reload", permissionDefault = PermissionDefault.OP)
    val reload = subCommand {
        execute<ProxyCommandSender> { sender, _, _ ->
            Configurations.reload()
            sender.castSafely<CommandSender>()?.let { Bukkit.dispatchCommand(it, "invsee reload") }
            Language.reload()
            TabooLib.lifeCycle(LifeCycle.LOAD)
            info("Reloaded by ${sender.name}")
            sender.sendLang("commands-luminus-reloadSuccess")
        }
    }

}